<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>注册 -智慧之窗乡村管理系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">

    <style>
        html, body {width: 100%; height: 100%; overflow: hidden}
        body {background: #1E9FFF;}
        body:after {content:''; background-repeat:no-repeat; background-size:cover; filter:blur(3px); position:absolute; top:0; left:0; right:0; bottom:0; z-index:-1;}
        .layui-container {width: 100%; height: 100%; overflow: hidden}
        .admin-login-background {width:360px; height:400px; position:absolute; left:50%; top:40%; margin-left:-180px; margin-top:-200px;}
        .logo-title {text-align:center; letter-spacing:2px; padding:14px 0;}
        .logo-title h1 {color:#1E9FFF; font-size:25px; font-weight:bold;}
        .login-form {background-color:#fff; border:1px solid #fff; border-radius:3px; padding:14px 20px; box-shadow:0 0 8px #eeeeee;}
        .login-form .layui-form-item {position:relative;}
        .login-form .layui-form-item label {position:absolute; left:1px; top:1px; width:38px; line-height:36px; text-align:center; color:#d2d2d2;}
        .login-form .layui-form-item input {padding-left:36px;}
        .error-msg {color: red; text-align: center; margin-bottom: 10px;}
    </style>
</head>
<body>
<div class="layui-container">
    <div class="admin-login-background">
        <div class="layui-form login-form">
            <form class="layui-form" action="/admin/registerUser" method="post">
                <div class="layui-form-item logo-title">
                    <h1>用户注册</h1>
                </div>
                <div class="error-msg" th:text="${msg}"></div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-username" for="adminname"></label>
                    <input id="adminname" type="text" name="adminname" required lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-password" for="password"></label>
                    <input id="password" type="password" name="password" required lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-password" for="confirm_password"></label>
                    <input id="confirm_password" type="password" name="confirm_password" required lay-verify="required|confirmPass" placeholder="确认密码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-group" for="role"></label>
                    <select id="role" name="role" required lay-verify="required" class="layui-input">
                        <option value="">请选择角色</option>
                        <option value="用户">用户</option>
                        <option value="管理员">管理员</option>
                    </select>
                </div>
<!--                <div class="layui-form-item">-->
<!--                    <label class="layui-icon layui-icon-cellphone" for="user_number"></label>-->
<!--                    <input type="text" name="user_number" required lay-verify="required|phone" placeholder="手机号" autocomplete="off" class="layui-input">-->
<!--                </div>-->
<!--                <div class="layui-form-item">-->
<!--                    <label class="layui-icon layui-icon-email" for="user_email"></label>-->
<!--                    <input type="email" name="user_email" required lay-verify="required|email" placeholder="邮箱" autocomplete="off" class="layui-input">-->
<!--                </div>-->
                <div class="layui-form-item">
                    <button id="btn-register" class="layui-btn layui-btn layui-btn-normal layui-btn-fluid" lay-submit="" lay-filter="/register">注册</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
<script th:src="@{/layui/layui.all.js}" charset="utf-8"></script>
<script th:src="@{/lib/jq-module/jquery.particleground.min.js}" charset="utf-8"></script>
<script th:inline="javascript">
    $(document).ready(function () {
        var ctxPath = /*[[@{/}]]*/ '/';


        // debugger;
        // // var adminname = $('#adminname').val();
        // $('#btn-register').on('click', function (data) {
        //     var adminname = $('#adminname').val();
        //     var password = $('#password').val();
        //     var confirm_password = $('#confirm_password').val();
        //     var role = $('#role').val();
        //     if (password !== confirm_password){
        //         layer.msg('两次密码输入不一致');
        //         return false;
        //     }else{
        //
        //         // var url = "/admin/register";
        //         datas= {
        //             adminname: adminname,
        //             password: password,
        //             role: role  ,
        //             confirm_password: confirm_password
        //         };
        //         datas=JSON.stringify(datas);
        //         debugger;
        //         $.ajax({
        //             type: 'POST',
        //             url: '/admin/registerUser',
        //             contentType: 'application/json',
        //             data: datas,
        //             dataType: 'json',
        //             success: function (result) {
        //                 debugger;
        //                 if (result.code === "1") {
        //                     layer.msg("注册成功");
        //                     console.log(result.msg, result.code);
        //                     window.location.href = ctxPath + "login";
        //                 } else {
        //                     layer.msg("注册失败");
        //                     console.log(result.msg, result.code);
        //
        //                 }
        //             },
        //             error: function (xhr, status, error) {
        //                 // layer.msg('请求失败，请稍后再试');
        //                 $("#btn-login").removeAttr("disabled").removeClass("layui-btn-disabled");
        //             }
        //         });
        //
        //     }
        //
        //
        //     return false;
        //
        // });


        $('#btn-register').on('click', function (event) {
            event.preventDefault(); // 阻止默认表单提交
            var adminname = $('#adminname').val();
            var password = $('#password').val();
            var confirm_password = $('#confirm_password').val();
            var role = $('#role').val();

            if (password !== confirm_password) {
                layer.msg('两次密码输入不一致');
                return false;
            }

            var datas = {
                adminname: adminname,
                password: password,
                confirm_password: confirm_password,
                role: role
            };

            $.ajax({
                type: 'POST',
                url: '/admin/registerUser',
                contentType: 'application/json',
                data: JSON.stringify(datas),
                dataType: 'json',
                success: function (result) {
                    if (result.code === "1") {
                        layer.msg("注册成功");
                        window.location.href = ctxPath + "login";
                    } else {
                        layer.msg(result.msg || "注册失败");
                    }
                },
                error: function (xhr, status, error) {
                    layer.msg('请求失败，请稍后再试');
                }
            });
        });
/*
        layui.use(['form', 'layer'], function () {
            var form = layui.form,
                layer = layui.layer;

            form.verify({
                confirmPass: function(value, item) { // value：表单的值、item：表单的DOM对象
                    if (value !== $('input[name="password"]').val()) {
                        return '两次密码输入不一致';
                    }
                }
            });


            // 注册操作
            // form.on('submit(register)', function (data) {
            //     var formData = data.field;
            //     $.post(ctxPath + "register", formData, function (result) {
            //         layer.msg(result.msg, {icon: result.icon, anim: result.anim});
            //         if (result.code === "1") {
            //             window.location.href = ctxPath + "login"; // 注册成功后跳转到登录页面
            //         }
            //     });
            //     return false;
            // });

            // 粒子线条背景
            $('.layui-container').particleground({
                dotColor:'#7ec7fd',
                lineColor:'#7ec7fd'
            });
        });*/
    });

</script>
</body>
</html>
